import {
  Controller,
  Get,
  Request,
  Post,
  UseGuards,
  Param,
  Body,
  Query,
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { AuthService } from './auth.service'
import { Public } from './set-public'

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) { }

  // 公开接口装饰器
  @Public()
  // 用户验证装饰器
  // @UseGuards(AuthGuard('local'))
  @Post('/login')
  // 账号密码验证
  login(@Body() body) {
    return this.authService.validateUser(body.userName, body.password)
  }

  @Post('userInfo')
  // 获取个人信息
  getProfile(@Body() body) {
    return this.authService.getUserInfo(body.id)
  }

  // 注册
  @Post('register')
  register(@Body() body) {
    return this.authService.register(body)
  }

  @Public()
  @Post('registerByAdmin')
  // 管理员注册
  registerByAdmin(@Body() body) {
    return this.authService.register(body)
  }

  // 删除
  @Post('delete')
  delete(@Body() body) {
    return this.authService.delete(body.id)
  }

  // 更新
  @Post('update')
  update(@Body() body) {
    return this.authService.update(body)
  }

  // 获取用户列表
  @Post('pages')
  pages(@Body() body) {
    return this.authService.pages(body)
  }

  // 修改用户信息
  @Post('edit')
  edit(@Body() body) {
    return this.authService.edit(body)
  }

  // 修改用户密码
  @Post('editPassword')
  editPassword(@Body() body) {
    return this.authService.editPassword(body)
  }
}
